import 'package:bxultimate/data/request/user_request.dart';
import 'package:bxultimate/data/store/auth_store.dart';
import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/shared/constant/app_constant.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'state.dart';

class UserAccountUpdatePasswordController extends GetxController {
  final UserAccountUpdatePasswordState state = UserAccountUpdatePasswordState();

  TextEditingController oldPasswordController = TextEditingController();
  TextEditingController newPasswordController = TextEditingController();
  TextEditingController confirmPasswordController = TextEditingController();

  // 修改密码

  updatePwd() async {
    Result result = await UserRequest.upPwdByPwd(AuthStore.to.profile.mobile,
        newPasswordController.text, confirmPasswordController.text);

    if (result.code == AppConstant.RESULT_ERROR) {
      SmartDialog.showNotify(msg: '原密码错误', notifyType: NotifyType.error);
      return;
    }

    SmartDialog.showToast('修改密码成功');
    Get.back();
  }
}
